<template>
	<el-row>
	  <el-col :span="11">
		  <div class="grid-content bg-purple l">
			  <h2>欢迎来到Vue管理系统</h2>
			  <el-image :src='require("@/assets/1.png") ' style="width:300px;height:300px;"></el-image>
			  <h3>欢迎来到管理</h3>
			  <h4>扫码二维码，关注tuple(吴某人)</h4>
		  </div>
	  </el-col>
	  <el-col :span="2">
			<div class="grid-content bg-purple-light">
				    <el-divider direction="vertical"></el-divider>

			</div>
	 </el-col>		
	  <el-col :span="11">
		  <div class="grid-content bg-purple-light r" >
				<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
				  <el-form-item label="用户" prop="user" >
				    <el-input v-model="ruleForm.user" style="width: 260px;"></el-input>
				  </el-form-item>
				  

				  <el-form-item label="密码" prop="password">
				    <el-input v-model="ruleForm.password" style="width: 260px;" ></el-input>
				  </el-form-item>
				  <el-form-item label="校验" prop="code">
				    <el-input v-model="ruleForm.code" style="width: 100px;" ></el-input>
					<el-image :src="captchaImg "></el-image>
				  </el-form-item>
				  <el-form-item>
				    <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
				    <el-button @click="resetForm('ruleForm')">重置</el-button>
				  </el-form-item>
				</el-form>
		  </div>
	  </el-col>
	</el-row>
</template>

<script>
  export default {
    data() {
      return {
        ruleForm: {
          user: '',
          password:'',
		  code:'',
		  token:''
        },
		captchaImg:null,
        rules: {
          user: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输入正确的密码', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          code: [
			{ required: true, message: '请输入正确的验证码', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          
        
        }
      };
    },
	created() {
			this.getcaptcha()
	},
    methods: {
      submitForm(formName) {
		
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$axios.post('/login',this.ruleForm).then(res=>{
				const jwt=res.headers['authorization']
				this.$store.commit('SET_TOKEN',jwt)
				this.$router.push('/index')
			})
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
	  
	  getcaptcha(){
		  this.$axios.get('/captcha').then(res=>{
			
				this.ruleForm.token=res.data.data.token
				this.captchaImg=res.data.data.captchaImg
				
				
		  })
		  
	  }
    }
  }
  
  
</script>

<style scoped>
	.l{
		float: right;
	}
	.r{
		float: left;
		left: -10px;
	}
	.el-col{
		align-items: center;
	}
	.el-row{
		display: flex;
		background-color: azure;
		position: fixed;
		height:100%;
		width: 100%;
		align-items: center;
		text-align: center;
		padding: 10%;
	}
	.el-divider{
		height: 300px;
		
	}
	.el-image{
		padding: 10px;
		border-radius: 8px;
	}
	.el-form-item{
		align-items:center;
	}
</style>